<extend name="Base/common" />
<block name="Content">
	<div class="am-cf am-padding-top">
		<div class="am-fl am-cf">
			<i class="am-icon-file"></i> <strong
				class="am-text-primary am-text-lg">超范围服务管理</strong>
		</div>
		<hr data-am-widget="divider" class="am-divider am-divider-default" />
	</div>
	
	<form class="am-form-horizontal" method="post" action="{:U('addAction')}">
		<input type="text" placeholder="0-3" name="charge" />
		<div class="am-btn-group am-btn-group-xs">
			<button type="submit" class="am-btn am-btn-success ajax-post"
				target-form="am-form-horizontal">
				<span class="am-icon-plus"></span>&nbsp;新增
			</button>
		</div>
		<hr data-am-widget="divider" class="am-divider am-divider-default" />
	</form>
	
	<table class="am-table am-table-striped am-table-hover table-main" id="table">
		<thead>
			<tr>
				<th class="table-check">
					<input type="checkbox" class="checkAll" />
				</th>
				<th class="table-title" style="width: 25%">范围最小值（单位：千米，包括）</th>
				<th class="table-title" style="width: 25%">范围最大值（单位：千米，不包括）</th>
				<th class="table-type" style="width: 25%">收费标准（元）</th>
				<th class="table-set" style="width: 20%">操作</th>
			</tr>
		</thead>
		<tbody>
			<notempty name="list"> 
				<foreach name="list" item="charge">
					<tr>
						<td>
							<input type="checkbox" value="{$charge.charge_id}" name="charge_ids[]" class="ck" /></td>
						<td>
							<input type="number" step="0.01" value="{$charge.minimum}" name="minimum" required />
						</td>
						<td>
							<input type="number" step="0.01" value="{$charge.maximum}" name="maximum" required />
						</td>
						<td>
							<input type="number" step="0.01" value="{$charge.price}" name="price" required />
						</td>
						<td>
							<div class="am-btn-toolbar">
								<div class="am-btn-group am-btn-group-xs">
									<a class="am-btn am-btn-default am-btn-xs am-text-secondary" name='update'>
										<span class="am-icon-pencil-square-o"></span>更新</a>
									<a class="am-btn am-btn-default am-btn-xs am-text-danger confirm ajax-get"
										href="{:U('delAction?charge_id='.$charge['charge_id'])}">
										<span class="am-icon-pencil-square-o"></span>删除</a>
								</div>
							</div>
						</td>
					</tr>
				</foreach> 
			<else />
				<td colspan="6" class="text-center">暂时还没有内容!</td>
			</notempty>
		</tbody>
	</table>
</block>
<block name="script"> <script type="text/javascript">
	$(function() {
		//修改子类型
		$("#table").each(function() {
			$("a[name=update]").click(function() {
				
				var idtd = $(this).parents("tr").find("td:eq(0)")//下标0开始
				var chargeID = idtd.find(".ck").val();
				var mintd = $(this).parents("tr").find("td:eq(1)");
				var minimum = mintd.find("input").val();
				var maxtd = $(this).parents("tr").find("td:eq(2)");
				var maximum = maxtd.find("input").val();
				var pricetd = $(this).parents("tr").find("td:eq(3)");
				var price = pricetd.find("input").val();
				
				if ($.AMUI && $.AMUI.validator) {
					var target = Think.U('Charge/saveAction');
					$.post(target, {'charge_id':chargeID, 'min': minimum, 'max':maximum, 'price':price}, function(data){

						if(data.status == 1){
							updateAlert('操作成功~', 'alert-success');
						}else{
							updateAlert('操作失败~');
						}
						
						setTimeout(function() {
							$('#top-alert').find('button').click();
						}, 1500);
					})
				}
			});
		});
	});
</script> </block>
